--
-- Author: shunguo.chen
-- Date: 2016-08-09 13:53:57
--
-- RewardOnlineRender

local IconRender = require("app.widget.renders.IconRender")

local ClassRef = app.mvc.createRenderClass(...)

--data = RewardOnlineVo
function ClassRef.create(node)
	local sprite = ClassRef.extend(node)
	-- if node == nil then
	-- 	ccui.Helper:doLayout(sprite)
	-- end
	sprite:init(data)
	return sprite
end

function ClassRef:init(data)
	self.super.init(self, data)

	self._ui.btn_enter:addClickEventListener(function()
			executeFunc(self._onBtnClick)
		end)

	self._items = {}
	for i=1,3 do
		local render = IconRender.create(self._ui["icon_" .. i])
		render:setTipEnable(true, {x=2/5,y=2/5})
		self._items[i] = render
	end

	self:refresh()
end

function ClassRef:refresh()
	if self._data then
		for i,item in ipairs(self._items) do
			local v = self._data.rewards[i]
			item:setVisible(v ~= nil)
			if v then
				item:setData(v)
			end
		end
		display.setBtnTouchEnable(self._ui.btn_enter, self._data:hasReward())
		self._ui.img:setColor(self._data:hasReward() and display.COLOR_WHITE or display.COLOR_GRAY)
	end
end

function ClassRef:onBtnClick(cb)
	self._onBtnClick = cb
end

return ClassRef
